package com.whiliong.jxc.action.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.handlers.HandlerUtil;

import com.whlilong.jxc.constants.IAppConstants;
import com.whlilong.jxc.input.BusinessInfoEditorInput;

public class BusinessInfoHandler extends AbstractHandler implements IHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		// TODO Auto-generated method stub
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		BusinessInfoEditorInput input = new BusinessInfoEditorInput();
		try{
			window.getActivePage().savePerspective();
			window.getActivePage().close();
			window.openPage(IAppConstants.editor_perspective, null);
			window.getActivePage().openEditor(input, IAppConstants.businessInfoEditor_id, true);
		}catch(PartInitException e){
			e.printStackTrace();
		}catch(WorkbenchException e){
			e.printStackTrace();
		}
		return null;
	}

}
